/**
 * 请求功能封装
 */

import axios from "axios";
import { getToken } from "@/utils/token.js";

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 5000,
});

// 拦截请求
service.interceptors.request.use((config) => {
  const token = getToken();
  if (token) {
    config.headers["authorization"] = token;
  }
  return config;
});

// 拦截响应
service.interceptors.response.use((response) => {
  const res = response.data;
  return res;
});

export default service;
